<template>
  <div class="login">
    <div class="flex box">
      <div class="item">
        <div v-for="v in list1" :style="'height:'+v" :key="v.index"></div>
      </div>
      <div class="item">
        <div v-for="v in list2" :style="'height:'+v" :key="v.index"></div>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "vant-green"
import { getUerInfo } from '../plugins/api'
export default {
  name: 'login',
  data(){
    return {
      list1:["3rem","2.5rem","4.5rem",'3rem',"2rem","4rem"],
      list2:[],
    }
  },
  methods:{
    queryUrl(args){
      let params = new URLSearchParams(window.location.search);
      return params.get(args);
    },
    goHome(){
      setTimeout(()=>{
        window.location.href = `${window.location.origin}/#/init`
      },50)
    }
  },
  mounted(){
    this.list2 = [...this.list1].reverse()
    // 如果为测试则直接赋值userid并跳转
    if(!window.verify){
      localStorage.setItem('userId',"011992")
      this.goHome()
      return false;
    }
    if(window.location.href.includes('code')){
      // 如果有code 则保存code 并跳转到init
      this.code = this.queryUrl('code')
      let formData = new FormData()
          formData.append('code',this.code)
      // 根据code获取 userid 
      getUerInfo(formData).then(res=>{
        if(res.code == 200) {
          this.userId = res.data.UserId
          localStorage.setItem('userId',this.userId)
          // 跳转到没有参数的地址
          this.goHome()
        }else{
          Toast(res.msg)
        }
      }).catch(err=>{
        Toast(`error:${err}`)
      })
    }
  }
}
</script>
<style scoped>
  .box {
    width: 7rem;
    margin:0 auto;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding-top: .5rem;
  }
  .item div {
    width: 100%;
    background-color: rgb(163, 195, 253,.1);
    border-radius: 0.3rem;
    margin-top: 0.2rem;
  }
  .item {
    width: 48%;
  }

</style>